from django.contrib import admin
from django.utils.safestring import mark_safe

from .models import Advertisement


@admin.register(Advertisement)
class AdvertisementAdmin(admin.ModelAdmin):
    """广告管理"""
    list_display=["position","source","adid","title","img_dis","begin_date","end_date"]
    list_display_links=["position",]


    def img_dis(self, obj):
        if obj.img:
            return mark_safe('<img src="%s" width="100px" />' % obj.img.url)

    img_dis.short_description = "图片"
    img_dis.allow_tags = True

